package com.bwie.seckill.controller;

import java.util.Arrays;
import java.util.Map;

import com.bwie.seckill.config.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.seckill.entity.ShopEntity;
import com.bwie.seckill.service.ShopService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 商品基本信息表
 *
 * @author gy
 * @email gy@gmail.com
 * @date 2022-06-19 20:25:20
 */
@RestController
@RequestMapping("seckill/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @Autowired
    private OssUtils ossUtils;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = shopService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{shopId}")
    public R info(@PathVariable("shopId") Integer shopId){
		ShopEntity shop = shopService.getById(shopId);

        return R.ok().put("shop", shop);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ShopEntity shop){
		shopService.save(shop);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ShopEntity shop){
		shopService.updateById(shop);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] shopIds){
		shopService.removeByIds(Arrays.asList(shopIds));

        return R.ok();
    }

    /**
     * 图片上传
     */
    @RequestMapping("/upload")
    public R upload(@RequestParam MultipartFile file){
        return ossUtils.uploadFile(file);
    }




}
